<?php

class Zend_View_Helper_ProfileLink
{
    public $view;

    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }

    public function profileLink()
    {
        $urlProfile = $this->view->url(array('action'=>'edit', 'controller'=>'users'), null, true);
        $urlLogin = $this->view->url(array('action'=>'index', 'controller'=>'login'), null, true);
        $urlLogout = $this->view->url(array('action'=>'logout', 'controller'=>'login'), null, true);
        $urlRegister = $this->view->url(array('action'=>'register', 'controller'=>'login'), null, true);

        $auth = Zend_Auth::getInstance();

        if ($auth->hasIdentity()) {
            $user = $auth->getIdentity();
            return 'Добре дошли, ' . $user->username . ' | ' .
                   '<a href="' . $urlProfile . '">Профил</a> | ' .
                   '<a href="' . $urlLogout . '">Изход</a>';
        } else {
            return '<a href="' . $urlLogin . '">Вход</a> | ' .
                   '<a href="' . $urlRegister . '">Регистрация</a>';
        }
    }
}